<?php 
	class 	Banner_model extends CI_Model
	{
		private $table = "no_banner";
	
		public function admin_save($file_name)
		{
			$id = intval($this->input->post('hidden_id'));
			if($this->input->post('status')=='on'){
				$status = 1;
			}else{
				$status = 0;
			}
			if($id == 0)
			{
				$data_content = array( 
					'parent_id' 		=> $this->input->post('parent_id'),
					'name' 				=> $file_name,
					'order'				=> $this->input->post('order'),
					'created_time' 		=> getNow(),
					'modified_time' 	=> getNow(),
					'status' 			=> $status
				);
			
				if($this->db->insert($this->table,$data_content)){
					return true;
				}
			}else{
				$image_mapping = $this->get_image_product($id);
				if($file_name == '')
				{
					$file_name = $image_mapping[0]['name'];
				}else{
					@unlink(IMAGE_LARGE_DIR.$image_mapping[0]['name']);
				}
				$data_content = array( 
					'parent_id' 		=> $this->input->post('parent_id'),
					'name' 				=> $file_name,
					'order'				=> $this->input->post('order'),
					'modified_time' 	=> getNow(),
					'status' 			=> $status				
				);
				
				$this->db->where('id',$id);
				if($this->db->update($this->table,$data_content)){
					return true;
				}
			}
		
			return false;
		}
		
		public function admin_index()
		{
			$this->db->select('*');
			$this->db->order_by('type','DESC');
			
			$query = $this->db->get($this->table);
			$result = $query->result();
			$query->free_result();
			
			return $result;
		}
		
		public function admin_update($id = 0)
		{
			$id = intval($id);
			$this->db->select('*');		
			$this->db->where('id',$id);
						
			$query = $this->db->get($this->table);
			$result = $query->result();
			$query->free_result();
			
			return $result;		
		}
		
		public function admin_del($id = 0)
		{
			$id = intval($id);

			$this->db->where('id',$id);
			if($this->db->delete($this->table))
			{
				return true;
			}
			return false;
		}
		
		public function admin_del_all()
		{
			$value	= array();
			$value  = $this->input->post('check_item');
			
			foreach($value as $val)
			{
				$this->db->where('id',$val);
				$this->db->delete($this->table);
				$array_del = array();
			}
		}
					
		function admin_update_status($id,$status)
		{
			$id = intval($id);
			
			$this->db->where('id',$id);
			$data = array('status'=>$status);
			
			if($this->db->update($this->table,$data))
			{
				return true;
			}else{
				return false;
			}
		}	
	}
?>